package com.jdjw.modules.service.impl;

import com.jdjw.common.ResponseResult;
import com.jdjw.modules.mapper.bidMapper;
import com.jdjw.modules.service.BidService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 页面展示接口service
 */
@Service
public class WebDisplayServiceImpl implements BidService {

    @Resource
    bidMapper bidMapper;

    private  final String appPath="http://218.108.73.50:8082/";

    /**
     * 获取单位详情
     * @return
     */
    @Override
    public ResponseResult getProjectData(String projectCode) {

        ResponseResult result = new ResponseResult();

        try{
            List<Map<Object,Object>> list = bidMapper.getProjectData(projectCode);
            for (Map<Object, Object> listObject : list) {
                listObject.replace("approval_record_form_id",getFilePath(listObject.get("approval_record_form_id").toString()));
                listObject.replace("publicity_file_id",getFilePath(listObject.get("publicity_file_id").toString()));
                listObject.replace("meeting_summary_id",getFilePath(listObject.get("meeting_summary_id").toString()));
            }
            result.setCode(200);
            result.setMsg("SUCCESS");
            result.setData(list);
        }
        catch (Exception e){
            e.printStackTrace();
            result.setCode(500);
            result.setMsg("ERROR");
            result.setData("请求失败");
        }
        return result;
    }
     public List<String> getFilePath(String fileId){
         List<String> list=new ArrayList<>();
         if(StringUtils.isEmpty(fileId)){
             return list;
         }
         String[] split = fileId.split(",");
         for (String s : split) {
            String filePath=bidMapper.selectAttachment(s);
             list.add(appPath+filePath);
         }
         return list;
     }

}
